/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.sesame.service.AdminService;
import com.sesame.service.AlbumService;

/**
 * @author voidman
 * 
 */

public class DeleteInfoController extends AbstractController {

    private AdminService adminService;
    private AlbumService albumService;

    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

    public void setAlbumService(AlbumService albumService) {
        this.albumService = albumService;
    }

    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse reponse) throws Exception {

        if ("admin".equals(request.getSession().getAttribute("adminRank"))) {
            String type = request.getParameter("type");
            if (type.equals("user")) {
                Integer userId = Integer.parseInt(request
                        .getParameter("userId"));
                adminService.deleteUser(userId);
            } else if (type.equals("album")) {
                Integer albumId = Integer.parseInt(request
                        .getParameter("albumId"));
                albumService.deleteAlbum(albumId);

            } else {
                Integer imageId = Integer.parseInt(request
                        .getParameter("imageId"));
                albumService.deleteImage(imageId);
            }

            return new ModelAndView("redirect:adminSearch.html");
        } else {
            return new ModelAndView("redirect:adminError.html");
        }

    }
}